package com.leetcode.LC;

import java.util.Arrays;

public class LC1608 {
    public int specialArray(int[] nums) {

        Arrays.sort(nums);
        int rs;
        for (int i = 1; i <= nums.length; i++) {
            rs = i;
            if (rs == toNum(nums, rs)) {
                return rs;
            }
        }
        return -1;
    }

    public int toNum(int[] nums, int tmp) {
        int count = 0;
        for (int num : nums) {
            if (tmp <= num) {
                count++;
            }
        }
        return count;
    }

    public static void main(String[] args) {
        System.out.println(new LC1608().specialArray(new int[]{23,35,37,55,67,29,41,81,36,5,17,21,1,63,3,46,58,29,23,77,61,52,42,50,49,69,34,4,22,0,40,31,18,66,63,7,49,70,70,34,22,68,50,45,28,46,46,72,4,82,45,54,12,2,15,56,82,17,3,58,60,28,12,76}));
    }
}
